package com.xc.videosample

import android.content.Context
import android.content.Intent
import android.media.MediaPlayer
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.view.accessibility.AccessibilityManager
import android.widget.MediaController.MediaPlayerControl
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.feo.kpler.FKerVideoProgressListener
import com.xc.videosample.databinding.ActivityVideoPlayerBinding

class VideoPlayerActivity : AppCompatActivity() {

    companion object {
        fun start(context: Context) {
            context.startActivity(Intent(context, VideoPlayerActivity::class.java))
        }
    }
    // 重定向地址 http://baobab.kaiyanapp.com/api/v1/playUrl?vid=2178&editionType=default&source=aliyun

    var videoUri =
        "http://baobab.kaiyanapp.com/api/v1/playUrl?vid=2178&editionType=default&source=aliyun"


    lateinit var dataBinding: ActivityVideoPlayerBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        videoUri = "http://127.0.0.1:34603/https%3A%2F%2Fcdn.gzzhitui.com%2Fjiliang-bucket%252Fcreative%252Fhuiyuan-hpageicon%252Fqumiao%252F1.%25E6%25B0%2591%25E9%2597%25B4%25E6%2595%2585%25E4%25BA%258B10s.mp4"

//        val url = Uri.parse("android.resource://" + packageName + "/" + R.raw.test_kekyboard)
//        dataBinding.playerView.start(videoUri)


        dataBinding =
            DataBindingUtil.setContentView(this, R.layout.activity_video_player)
        dataBinding.playerView.setCoverUrl("https://pics5.baidu.com/feed/6d81800a19d8bc3e5450a6ed86a98910a8d34569.jpeg@f_auto?token=fcd23ccd1d63fa668759b7e3ec44bbbb")
        dataBinding.playerView.setUseCache(true)
        dataBinding.playerView.showController(true)
        dataBinding.playerView.start(videoUri)

//        dataBinding.playerView.startUri(url)
//        dataBinding.playerView.videoView.seekTo(3)
        dataBinding.playerView.postDelayed(
            { dataBinding.playerView.visibility = View.VISIBLE },
            15
        )



        dataBinding.btnStart.setOnClickListener {
            dataBinding.playerView.start(videoUri)
        }
        dataBinding.btnPause.setOnClickListener {

            dataBinding.playerView.activePause()
        }

        dataBinding.btnResume.setOnClickListener {
            dataBinding.playerView.activeResume()
        }
        dataBinding.btnReplay.setOnClickListener {
            dataBinding.playerView.replay()

        }

        dataBinding.playerView.registerProgressListener(object : FKerVideoProgressListener {
            override fun start() {

            }

            override fun onProgress(currentPosition: Int, duration: Int) {
            }

            override fun complete() {
                dataBinding.playerView.replay()
            }

        })

        dataBinding.btnSoundOff.setOnClickListener {
            dataBinding.playerView.soundOff()
        }
        dataBinding.btnSoundOn.setOnClickListener {
            dataBinding.playerView.soundOn()
        }


    }

    override fun onResume() {
        super.onResume()
    }

    override fun onPause() {
        super.onPause()
    }


}